home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / msjv6-5.zip / WINDOS.ZIP / WMHANDLR.C < prev    next >
C/C++ Source or Header  |  1991-09-01  |  3KB  |  74 lines

  1. /*
  2. WMHANDLR.C
  3. Event (WM_ message) handlers - implementation
  4. Dave Maxey and Andrew Schulman - 1991
  5. originally published in Microsoft Systems Journal, July 1991
  6. */
  7.  
  8. #include <windows.h>
  9. #include "wmhandlr.h"
  10.  
  11. long            defwmhandler(HWND, unsigned, WORD, LONG);
  12.  
  13. WMHANDLER       wmhandler[WM_USER];
  14.  
  15. /* -----------------------------------------------------------------------  */
  16. /* This is our event processor. It is the dispatcher for the handlers set   */
  17. /* using SetHandler. An Application plugs this function into its            */
  18. /* window, sets handlers for messages, and WndProc handles the rest.        */
  19. /* This window procecedure should never need to be changed!                 */
  20. /* -----------------------------------------------------------------------  */
  21. long FAR PASCAL _export WndProc(HWND hWnd, WORD message, 
  22.     WORD wParam, LONG lParam)
  23.     {
  24.     if (message < WM_USER)
  25.         return (*wmhandler[message])(hWnd, message, wParam, lParam);
  26.     else
  27.         return DefWindowProc(hWnd, message, wParam, lParam);
  28.     }
  29.  
  30. /* ---------------------------------------------------------------- */
  31. /* Routines to get and set the message handlers. Setting to NULL    */
  32. /* uninstalls a handler, by setting the handler to the default      */
  33. /* which calls Windows own DefWndProc.                              */
  34. /* ---------------------------------------------------------------- */
  35. WMHANDLER wmhandler_get(unsigned message)
  36.     {
  37.     return (message < WM_USER) ? wmhandler[message] : 0;
  38.     }
  39.  
  40. WMHANDLER wmhandler_set(unsigned message, WMHANDLER f)
  41.     {
  42.     WMHANDLER oldf;
  43.     if (message < WM_USER)
  44.         {
  45.         oldf = wmhandler[message];
  46.         wmhandler[message] = f ? f : defwmhandler;
  47.         return (oldf ? oldf : defwmhandler);
  48.         }
  49.     else
  50.         return 0;
  51.     }
  52.  
  53. /* ----------------------------------------------------------------------- */
  54. /* This is a default handler so that an application chain on to a previous */
  55. /* handler from their current one without having to worry what was there   */
  56. /* before. All this default handler does is to call DefWindowProc.         */
  57. /* ----------------------------------------------------------------------- */
  58. long defwmhandler(HWND hwnd, unsigned message, WORD wParam, LONG lParam)
  59.     {   
  60.     return DefWindowProc(hwnd, message, wParam, lParam);
  61.     }
  62.  
  63. /* -------------------------------------------------------------------  */
  64. /* MUST BE CALLED BEFORE THE APPLICATION WINDOW IS CREATED -            */
  65. /* Just inits the array of handlers to the default..                    */
  66. /* -------------------------------------------------------------------  */
  67. void wmhandler_init(void)
  68.     {
  69.     WMHANDLER *pwm;
  70.     int i;
  71.     for (i=0, pwm=wmhandler; i < WM_USER; i++, pwm++) 
  72.         *pwm = defwmhandler;
  73.     }
  74.